package com.linjinp.study.动态代理;

/**
 * @Author: linjinp
 * @Date: 2021/6/2 13:52
 */
public class ProxyMain {
    /**
     * JDK 动态代理示例
     * @return
     */
    public static String jdkProxy() {
        JdkLogTestProxy log = new JdkLogTestProxy();
        // 获取代理对象
        LogTestService service = (LogTestService) log.creatProxyObject(new LogTestServiceImpl());
        System.out.println("调用 printBegin");
        service.printBegin();

        System.out.println("调用 printLog");
        service.printLog("打印日志");
        return "hellow world!!!!";
    }

    /**
     * Cglib 动态代理示例
     * @return
     */
    public static String cglibProxy() {
        CglibLogTestProxy log = new CglibLogTestProxy();
        // 获取代理对象
        LogTestService service = (LogTestService) log.getCglibProxy(new LogTestServiceImpl());
        System.out.println("调用 printBegin");
        service.printBegin();

        System.out.println("调用 printLog");
        service.printLog("打印日志");
        return "hellow world!!!!";
    }

    public static void main(String[] args) {
        jdkProxy();
        System.out.println("=================================");
        cglibProxy();
    }
}
